﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace PuzzleMaker
{
    public class Selection
    {
        private bool enabled;
        private bool snapToGrid;
        private Point startPosition;
        private Point endPosition;
        private Size gridSize;

        public Selection(int gridWidth = 1, int gridHeight = 1)
        {
            enabled = false;
            SnapToGrid = true;
            gridSize = new Size(gridWidth, gridHeight);
        }

        public bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }
        public bool SnapToGrid
        {
            get { return snapToGrid; }
            set { snapToGrid = value; }
        }
        public Point Start
        {
            get { return startPosition; }
            set
            {
                startPosition = value;
                if (snapToGrid)
                {
                    startPosition.X -= value.X % gridSize.Width;
                    startPosition.Y -= value.Y % gridSize.Height;
                }
            }
        }
        public Point End
        {
            get { return endPosition; }
            set
            {
                endPosition = value;
                if (snapToGrid)
                {
                    endPosition.X += gridSize.Width - (value.X % gridSize.Width);
                    endPosition.Y += gridSize.Height - (value.Y % gridSize.Height);
                }
            }
        }
        public Size GridSize
        {
            get { return gridSize; }
            set { gridSize = value; }
        }

        public int Width()
        {
            return Math.Abs(endPosition.X - startPosition.X);
        }

        public int Height()
        {
            return Math.Abs(endPosition.Y - startPosition.Y);
        }
    }
}
